package view.panel.result
{
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import global.GameType;
	import global.Message;
	
	import model.result.ResultData;
	
	import utils.DisplayTool;
	import utils.TextTool;
	
	import view.components.LabelButton;

	public class ResultItem extends Sprite
	{
		private static var winImg:LabelButton;
		private static var fireImg:LabelButton;
		private var springImg:LabelButton;
		private static var escapeImg:LabelButton;
		
		private var nameText:TextField;
		private var moneyText:TextField;
		
		public function ResultItem()
		{
			initButton();
			initText();
		}
		
		private function initButton():void
		{
			if (winImg == null)
			{
				winImg = new LabelButton(178,0,0,null,"panel_win");
				winImg.info = Message.RESULT_WIN_HINT;
				fireImg = new LabelButton(178,0,1,null,"panel_fire");
				fireImg.info = Message.RESULT_FIRE_HINT;
				
				escapeImg = new LabelButton(178,0,3,null,"panel_escape");
				escapeImg.info = Message.RESULT_ESCAPE_HINT;
			}	
			springImg = new LabelButton(178,0,2,null,"panel_spring");
			springImg.info = Message.RESULT_SPRING_HINT;
		}
		
		private function initText():void
		{
			nameText = TextTool.getTextField(100,20,12,0xFFFFFF);
			moneyText = TextTool.getTextField(100,20,12,0xFFFFFF);
			moneyText.x = 100;
			
			addChild(nameText);
			addChild(moneyText);
		}
		
		public function update(resultData:ResultData):void
		{
			nameText.text = resultData.playerName;
			if (resultData.moneyChange > 0)
			{
				moneyText.text = "+" + resultData.moneyChange;
			}
			else
			{
				moneyText.text = resultData.moneyChange.toString();
			}
			
			switch (resultData.resultState)
			{
				case GameType.RESULT_FIRE:
					addChild(fireImg);
					break;
				case GameType.RESULT_SPRING:
					addChild(springImg);
					break;
				case GameType.RESULT_WIN:
					addChild(winImg);
					break;
				case GameType.RESULT_ESCAPE:
					addChild(escapeImg);
					break;
			}
		
		}
		
		public function hint():void
		{
			with(this.graphics)
			{
				clear();
				beginFill(0xaaaaaa,.5);
				drawRoundRect(0,0,this.width,this.height,4,4);
				endFill();
			}
		}
		
		public function clear():void
		{
			this.graphics.clear();
			moneyText.text = "";
			nameText.text = "";
			DisplayTool.removeChild(this,fireImg);
			DisplayTool.removeChild(this,springImg);
			DisplayTool.removeChild(this,winImg);
			DisplayTool.removeChild(this,escapeImg);
		}
	}
}